<template>
  <div>
    <van-nav-bar title="我的收藏"
                 left-arrow
                 @click-left="$router.back()" />
    <van-swipe-cell v-for="item in starList"
                    :key="item.id">
      <!-- <van-card> -->
      <NewsItem :news="item" />
      <!-- </van-card> -->
      <template #right>
        <van-button square
                    text="删除"
                    @click="delStar(item.id)"
                    type="danger"
                    class="delete-button" />
      </template>
    </van-swipe-cell>

  </div>
</template>

<script>
import NewsItem from '../components/NewsItem.vue'
import { user_star, post_star } from '../api/news'
export default {
  components: { NewsItem },
  created() {
    user_star().then((res) => (this.starList = res.data.data))
  },
  data() {
    return {
      starList: [],
    }
  },
  methods: {
    delStar(id) {
      post_star(id).then((res) => {
        this.$toast.success(res.data.message)
        user_star().then((res) => (this.starList = res.data.data))
      })
    },
  },
}
</script>

<style lang="less" scoped>
/deep/.van-nav-bar {
  .van-icon {
    color: #000;
  }
}
.goods-card {
  margin: 0;
  background-color: #fff;
}

.delete-button {
  height: 100%;
}
</style>